/*
 * @Author: jlzm
 * @Date: 2020-04-26 14:31:09
 * @LastEditors: jlzm
 * @LastEditTime: 2020-06-22 09:33:06
 * @FilePath: \MPShop\mixins\goods\goods.js
 */
import {
    queryGoodsList
} from "@/lib/api/goodsServer/goods";
export default {
    data() {
        return {
            currentPage: 1,
            goodsList: []
        };
    },

    methods: {
        /**
         * @Function
         * @param { Object }  propsData - 请求配置项
         * @prop { Number }  propsData.activityType - 活动类型 0: 无活动, 10: 拼团, 20: 砍价
         * @prop { String }  propsData.goodsName    - 模糊查询名称
         * @prop { String }  propsData.goodsTypeId  - 商品类别id
         * @prop { String }  propsData.sortItem - 排序项 404710: 价格排序, 404720: , 404730: 上架时间排序
         * @prop { Number }  propsData.sortType - 排序类型 30: 升序, 40: 降序
         * @prop { Number }  propsData.status   - 状态 10: 上架, 15售罄, 20下架
         * @prop { Number }  propsData.currentPage - 当前页面
         */
        async getGoodsListAll(propsData = {}) {
            this.loadingType = "loading";
            propsData.activityType = propsData.activityType || '';
            propsData.goodsName = propsData.goodsName || "";
            propsData.goodsTypeId = propsData.goodsTypeId || "";
            propsData.sortItem = propsData.sortItem || "404730";
            propsData.sortType = propsData.sortType || 40;
            propsData.status = propsData.status || 10;
            propsData.currentPage = propsData.currentPage || this.currentPage || '';

            const {
                data
            } = await queryGoodsList(propsData);
            if (propsData.currentPage === 1) {
                this.goodsList = data.list;
            } else {
                this.goodsList = this.goodsList.concat(data.list);
            }
            const noMore = this.goodsList.length >= data.total;
            this.loadingType = noMore ? "noMore" : "more";
            uni.stopPullDownRefresh();
        }
    }
};